package com.example.demothree.service.imp;

import com.example.demothree.bean.Goods;
import com.example.demothree.bean.PurchaseItem;
import com.example.demothree.bean.PurchaseOrder;
import com.example.demothree.bean.ReturnOrder;
import com.example.demothree.dao.GoodsDao;
import com.example.demothree.dao.PurchaseItemDao;
import com.example.demothree.dao.ReturnOrderDao;
import com.example.demothree.dao.PurchaseOrderDao;
import com.example.demothree.exception.ServiceException;
import com.example.demothree.service.PurService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class PurServiceImp implements PurService {
    @Resource
    private PurchaseOrderDao purchaseOrderDao;
    @Resource
    private ReturnOrderDao returnOrderDao;
    @Resource
    private GoodsDao goodsDao;
    @Resource
    private PurchaseItemDao purchaseItemDao;
    //采购订单
    @Override
    public Page<PurchaseOrder> purcgdd(Integer pageNum,Integer pageSize) {
        Pageable pageable = PageRequest.of(pageNum,pageSize);
        Page<PurchaseOrder> page ;
        page = purchaseOrderDao.findAll(pageable);
        return page;
    }
    //id查询订单
    @Override
    public PurchaseOrder findById(Long id) {
        return purchaseOrderDao.findBy(id);
    }
    //添加订单
    @Override
    public PurchaseOrder adddd(PurchaseOrder purchaseOrder) {
        return purchaseOrderDao.save(purchaseOrder);
    }
    //采购退货
    @Override
    public Page<ReturnOrder> purcgth(Integer page,Integer size) {
        Pageable pageable = PageRequest.of(page,size);
        Page<ReturnOrder> page1 = returnOrderDao.findAll(pageable);
        return page1;
    }
    //根据id查询退货订单
    @Override
    public ReturnOrder getIdcgdd(Long id) {
        return returnOrderDao.findthBy(id);
    }
    //添加退货订单
    @Override
    public ReturnOrder addcgth(ReturnOrder returnOrder) {
        return returnOrderDao.save(returnOrder);
    }

    //删除退货订单
    @Override
    public void deletecgth(Long id) {
        returnOrderDao.deleteById(id);
    }
    //删除采购订单
    @Override
    public void deletucgdd(Long id) {
        purchaseOrderDao.deleteById(id);
    }
    //添加订单
    @Override
    public ReturnOrder addcgdd(ReturnOrder returnOrder) {
        return null;
    }
    //修改订单
    @Override
    public ReturnOrder updatecgdd(ReturnOrder returnOrder) {
        return null;
    }
    //添加商品
    @Override
    public Goods saveGoods(Goods goods) throws Exception{
        return goodsDao.save(goods);
    }
    //添加商品
    @Override
    public PurchaseItem savePurchaseItem(PurchaseItem purchaseItem) {
        return purchaseItemDao.save(purchaseItem);
    }
    //name查询商品
    @Override
    public Goods findByName(String name) {
        return goodsDao.findGoodsByName(name);
    }
}
